package whf.framework.ext.service;

import java.util.List;

import whf.framework.exception.FindException;
import whf.framework.exception.ServiceNotFoundException;
import whf.framework.ext.dao.DictItemDAO;
import whf.framework.ext.entity.Category;
import whf.framework.ext.entity.DictItem;
import whf.framework.util.BeanFactory;
import whf.framework.util.StringUtils;

/**
 * @author wanghaifeng
 * @email king@126.com
 * @modify 2006-06-16
 */
public class DictItemServiceImp extends whf.framework.service.ServiceImp<DictItem> implements DictItemService {

	private DictItemDAO dictItemDAO;

	public void setDictItemDAO(DictItemDAO dictDAO) {
		this.dictItemDAO = dictDAO;
	}

	public static DictItemService getDictService() throws ServiceNotFoundException {
		return (DictItemService)BeanFactory.getService(DictItemServiceImp.class) ;
	}

	public List<DictItem> findByCategory(Category category) throws FindException {
		return dictItemDAO.findByCategory(category);
	}

	/* (non-Javadoc)
	 * @see whf.framework.ext.service.DictItemService#findByCategory(whf.framework.ext.entity.Category, java.lang.String)
	 */
	public List<DictItem> findByCategory(Category category, String queryString) throws FindException {
		if(!StringUtils.isEmpty(queryString)){
			queryString += " and t.category = ?";
		} else {
			queryString = " t.category = ?";
		}
		return this.dictItemDAO.find(queryString, category);
	}

} 